package com.gu.controller;

import com.gu.entity.vo.PermissionVo;
import com.gu.service.AclPermissionService;
import com.gu.service.AclRolePermissionService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Description:  菜单权限分配
 *
 * @Autor: Rolin
 * datetime: 07-05-19:48
 */
@RestController
@Api(tags = "权限管理控件")
@CrossOrigin
@RequestMapping("/edu/adminManagement")
public class PermissionController {

    @Resource
    private AclPermissionService aclPermissionService;

    @Resource
    private AclRolePermissionService aclRolePermissionService;

    @ApiOperation("查询所有菜单目录")
    @GetMapping("/getAllAdmin")
    public CommonResult getAllAdmin() {

        PermissionVo permissionVo = aclPermissionService.getAll();
        return StringUtils.isEmpty(permissionVo) ? CommonResult.error() : CommonResult.success().data("permissionVo", permissionVo);

    }

    @ApiOperation("根据id递归删除菜单")
    @DeleteMapping("deleteById/{id}")
    public CommonResult deleteById(@PathVariable("id") String id) {

        boolean result = aclPermissionService.deleteById(id);
        return result ? CommonResult.success() : CommonResult.error();

    }


    @ApiOperation("给角色分配权限菜单")
    @PostMapping("/doAssign")
    public CommonResult doAssign(String roleId, String[] permissionIds) {

        aclRolePermissionService.saveRolePermissionRelationShip(roleId, permissionIds);
        return CommonResult.success();
    }


}
